﻿using BS.Infra;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BS.Write.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class RBACController : ControllerBase
    {
        private readonly IMediator _mediator;

        public RBACController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> AddUserToRole(AddUserToRoleCommand command)
        {
           return  await _mediator.Send(command);
        }

        /// <summary>
        /// 新增()
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult> AddRoleToPermissions(AddRoleToPermissionsCommand command)
        {
            return await _mediator.Send(command);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<ApiResult> RemoveUserFromRole([FromQuery]RemoveUserFromRoleCommand parm)
        {
            return await _mediator.Send(parm);
        }
        /// <summary>
        /// 回显（反填）
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult> BackTwoById([FromQuery]BackfillUserFromRoleCommand parm)
        {
            return await _mediator.Send(parm);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<ApiResult> UpdateUserToRole(UpdateUserToRoleCommand command)
        {
            return await _mediator.Send(command);
        }
    }
}
